import { BASE_URL } from '@/config';
import { request } from '@/utils/request';
import { MOCK_MERCHANT_DETAIL, MOCK_CATEGORIES } from './mockData';

/**
 * 商家相关接口
 */

// 开发模式开关（true: 使用Mock数据，false: 使用真实接口）
const USE_MOCK = true;

// 根据商家ID查询商家详情
export function getMerchantDetail(merchantId: string) {
if (USE_MOCK) {
    return Promise.resolve(MOCK_MERCHANT_DETAIL);
  }

  return request({
    url: `${BASE_URL}/user/merchants/nearby/detail/${merchantId}`,
    method: 'GET'
  });
}

// 根据商家ID获取所有分类及商品
export function getMerchantCategories(merchantId: string) {
if (USE_MOCK) {
    return Promise.resolve(MOCK_CATEGORIES);
  }

  return request({
    url: `${BASE_URL}/user/merchants/nearby/detail/${merchantId}/categories`,
    method: 'GET'
  });
}

// 根据商家ID和分类ID查询菜品列表
export function getProductsByCategory(merchantId: string, categoryId: string) {
  return request({
    url: `${BASE_URL}/user/merchants/nearby/detail/${merchantId}/category/${categoryId}/products`,
    method: 'GET'
  });
}

// 根据productId查看菜品详情
export function getProductDetail(productId: string) {
  return request({
    url: `${BASE_URL}/user/merchants/nearby/product/${productId}/detail`,
    method: 'GET'
  });
}

// 根据区域ID查询附近商家
export function getMerchantsByRegion(regionId: string) {
  return request({
    url: `${BASE_URL}/user/merchants/nearby/by-region/${regionId}`,
    method: 'GET'
  });
}

// 根据区域ID与商家类型查询附近商家
export function getMerchantsByRegionAndType(regionId: string, type: string) {
  return request({
    url: `${BASE_URL}/user/merchants/nearby/by-region/${regionId}/type/${type}`,
    method: 'GET'
  });
}

// 根据当前用户获取区域id
export function getCurrentRegionId() {
  return request({
    url: `${BASE_URL}/user/merchants/nearby/get-regionId/by-current`,
    method: 'GET'
  });
}